# -*- coding: utf-8 -*-
# @Time : 2022/6/22 22:13
# @Author : cheney
# @File : buzzerController.py
# @Software: PyCharm
# @Site: www.cheney.cc
"""
    蜂鸣器模块
    既提供控制蜂鸣器响的基本函数
    也提供关机、网络断开、有障碍等程序化的响声
"""
from pi.dao.buzzerDao import buzzerDao
import threading


class buzzerController:
    _buzzer = buzzerDao()

    def _ring_base(self, sound=500, times=5, sleep1=0.2, sleep2=0.1):
        # threading.Thread(target=self._buzzer.ring_dao, args=(sound, times, sleep1, sleep2,)).start()
        self._buzzer.ring_dao(sound, times, sleep1, sleep2)

    def on_boot(self):
        self._ring_base()

    def on_network_connected(self):
        for i in range(100, 1100, 100):
            self._ring_base(sound=i, times=1, sleep1=0.06, sleep2=0)

    def on_short_distance(self):
        self._ring_base()

    def on_network_disconnected(self):
        for i in range(100, 1100, 100):
            self._ring_base(sound=1100 - i, times=1, sleep1=0.06, sleep2=0)
